﻿namespace Ast.Core.Pe
{
    public class ExportedFunction
    {
        public ExportedFunction(uint address, int ordinal)
        {
            Rva = address;
            Ordinal = ordinal;
        }

        public ExportedFunction(uint rva, int ordinal, string name, string forwardModuleName, string forwardFunctionName)
            : this(rva, ordinal)
        {
            DecoratedName = name;
            ForwardModuleName = forwardModuleName;
            ForwardFunctionName = forwardFunctionName;
        }

        public uint Rva { get; private set; }

        public string DecoratedName { get; private set; }

//        public string UndecoratedName
//        {
//            get
//            {
//                if (this.DecoratedName == null) return null;
//                return DebugHelper.UndecorateSymbolName(this.DecoratedName);
//            }
//        }

        public int Ordinal { get; private set; }

        public bool IsForwarded
        {
            get { return ForwardFunctionName != null; }
        }

        public string ForwardModuleName { get; private set; }

        public string ForwardFunctionName { get; private set; }

        public override string ToString()
        {
            return ForwardFunctionName != null
                ? string.Format("Address=0x{0:X8}, Ordinal={1}, Name={2} => {3}.{4}", Rva, Ordinal, DecoratedName, ForwardModuleName, ForwardFunctionName)
                : string.Format("Address=0x{0:X8}, Ordinal={1}, Name={2}", Rva, Ordinal, DecoratedName);
        }
    }
}